package com.core.family.admin.controller;

import com.core.family.admin.domain.FileLogic;
import com.core.family.admin.domain.req.UcFileStorageReq;
import com.core.family.admin.service.FileLogicService;
import com.core.family.admin.service.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

import com.core.common.annotation.MenuDesc;
import com.core.common.domain.response.R;
import io.swagger.annotations.Api;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author honglei
 * @version 1.0
 * @time: 2024-4-25 15:47:47
 * @Description 服务实现层 文件逻辑存储
 */
@MenuDesc(desc = "文件逻辑存储", code = "FileLogic")
@Api(tags = "FileLogicController 文件逻辑存储")
@RestController
@RequestMapping("/api/FileLogic/")
public class FileLogicController {

    @Autowired
    FileLogicService service;


    /**
     * 新增
     *
     * @param bean
     * @return
     */
    @PostMapping(value = "create")
    public R create(MultipartFile file, String id) throws IOException {
        FileLogic bean = service.saveFile(file, id);
        return R.ok(bean);
    }

    /**
     * 删除
     *
     * @param request
     * @param id
     * @return
     */
    @PostMapping(value = "del/{id}")
    public R del(HttpServletRequest request, @PathVariable("id") Long id) {
        return R.ok(service.removeById(id));
    }

    /**
     * 批量删除
     *
     * @param request
     * @param ids
     * @return
     */
    @PostMapping(value = "batch/del")
    public R batchDel(HttpServletRequest request, @RequestBody List
            <String> ids) {
        return R.ok(service.removeByIds(ids));
    }


    @Autowired
    FileStorageService storageService;

    /**
     * 分页查询
     *
     * @return
     */
    @RequestMapping(value = "getStoragePage", method = {RequestMethod.GET, RequestMethod.POST})
    public R getPage(@RequestBody UcFileStorageReq queryReq) {

        return R.ok(storageService.selectPage(queryReq));
    }

}
